/*-
 * CPINStatus.java
 *
 * $LastChangedBy:  $
 * $LastChangedRevision:  $
 * $LastChangedDate:  $
 * $HeadURL: $
 *
 * Copyright (c) 2008, Stein Gunnar Bakkeby
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of Stein Gunnar Bakkeby nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.googlecode.attention.at;

public enum CPINStatus {

  READY("READY", "PIN has already been entered. No further entry needed."),
  SIM_PIN("SIM PIN", "ME is waiting for SIM PIN"),
  SIM_PUK("SIM PUK", "ME is waiting for SIM PUK"),
  PH_SIM_PIN("PH-SIM PIN", "ME is waiting for SIM PUK (antitheft)"),
  PH_SIM_PUK("PH-SIM PUK", "ME is waiting for SIM PUK (antitheft)"),
  SIM_PIN2("SIM PIN2", "PIN2, e.g. for editing the FD phonebook, only if preceding command was acknowledged with +CME ERROR: 17"),
  SIM_PUK2("SIM PUK2", "Only if preceding command was acknowledged with error +CME ERROR: 18"),
  PH_FSIM_PIN("PH-FSIM PIN", "ME is locked to very first SIM card and waiting for phone-to-very-first-SIM card password (factory personalisation)"),
  PH_FSIM_PUK("PH-FSIM PUK", "ME is waiting for phone-to-very-first-SIM card unblocking password to be given"),
  PH_NET_PIN("PH-NET PIN", "ME is waiting for network personalisation password"),
  PH_NET_PUK("PH-NET PUK", "ME is waiting for network personalisation unblocking password"),
  PH_NS_PIN("PH-NS PIN", "ME is waiting for network subset personalisation password"),
  PH_NS_PUK("PH-NS PUK", "ME is waiting for network subset unblocking password"),
  PH_SP_PIN("PH-SP PIN", "ME is waiting for service provider personalisation password"),
  PH_SP_PUK("PH-SP PUK", "ME is waiting for service provider personalisation unblocking password"),
  PH_C_PIN("PH-C PIN", "ME is waiting for corporate personalisation password"),
  PH_C_PUK("PH-C PUK", "ME is waiting for corporate personalisation unblocking password"),
  ERROR("ERROR", "Unknown CPIN response");
  
  private final String identifier;
  private final String description;
  
  private CPINStatus(final String identifier, final String description) {
    this.identifier = identifier;
    this.description = description;
  }
  
  public String getDescription() {
    return description;
  }
  
  public static CPINStatus parse(String code) {
    if (code == null) throw new NullPointerException("CPINStatus.parse(null)");
    code = code.toUpperCase().trim();
    CPINStatus output = ERROR;
    for (CPINStatus status : CPINStatus.values()) {
      if (code.equals(status.identifier)) {
        output = status;
        break;
      }
    }
    return output;
  }
}
